<?php
namespace backend\models;

use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\base\Model;
use yii\web\IdentityInterface;

/**
 * Departments model
 *显示字段

 */
class LoginLog extends ActiveRecord
{
    const STATUS_DELETED = 0;
    const STATUS_ACTIVE = 10;


    /**
     * @inheritdoc
     */
     
    public static function tableName()
    {
        return '{{%login_log}}';
    }
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

  /* public function rules(){
        return [
            [['grade','departName','departPcount','parentId','isDelete','isEnable'],'required']
        ];
    }*/
    /**
     * @inheritdoc
     */
    	public function behaviors()
	{
		return [
				'timestamp' => [
						'class' => 'yii\behaviors\TimestampBehavior',
						'attributes' => [
								ActiveRecord::EVENT_BEFORE_INSERT => [
										
										
								],
								ActiveRecord::EVENT_BEFORE_UPDATE => [
										 
								] 
						] 
				] 
		];
	}

    /**
     * @inheritdoc
     */
   /* public function rules()
    {
        return [
            ['status', 'default', 'value' => self::STATUS_ACTIVE],
            ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
        ];
    }
   */

    /**
     * @inheritdoc
     */
    public static function findIdentity($id)
    {
        return static::findOne(['id' => $id]);
    }

    /**
     * 获取登录日志列表
     */
    public static function getLoginLogList(){
        return static::find()->asArray()->all();
    }
    /**
     * 新增日志
     */
    public  function addLoginLog($loginName,$adminId){
        $ip=get_real_ip();
        $this->loginName=$loginName;
        $this->adminId=$adminId;
        $this->loginIp=$ip;
        $addressInfo=getAddressInfo($ip);
        $this->loginAddress=$addressInfo['province'].'-'.$addressInfo['city'];
        $this->loginTime=time();
        $this->save();
    }



}
